package com.woniuxy.factory.service.imp;

import com.woniuxy.factory.entity.Equipment;
import com.woniuxy.factory.entity.EquipmentType;
import com.woniuxy.factory.mapper.EquipmentMapper;
import com.woniuxy.factory.mapper.EquipmentTypeMapper;
import com.woniuxy.factory.service.EquipmentTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EquipmentTypeServiceImp implements EquipmentTypeService {
    @Autowired
    EquipmentTypeMapper equipmentTypeMapper;
    @Autowired
    EquipmentMapper equipmentMapper;

    @Override
    public List<EquipmentType> findEquipment() {
        //查询出所有设备类型
        List<EquipmentType> equipmentTypes = equipmentTypeMapper.selectEquipment();
        //查询出所有设备类型对应设备台数
        Equipment equipment = new Equipment();
        Integer count;
        //查询出该类型设备对应的数量
        for (EquipmentType equipmentType : equipmentTypes) {
            equipment.setTid(equipmentType.getTid());
            count = equipmentMapper.totalEquipmentByCondition(equipment);
            equipmentType.setEnumber(count);
        }
        return equipmentTypes;
    }

    @Override
    public void addEquipmentType(EquipmentType equipmentType) {
        equipmentTypeMapper.insertEquipmentType(equipmentType);
    }

    @Override
    public void modifyEquipmentType(EquipmentType equipmentType) {
        equipmentTypeMapper.updateEquipmentType(equipmentType);
    }

    @Override
    public void deleteEquipmentTypeByTid(int tid) {
        equipmentTypeMapper.deleteEquipmentTypeByTid(tid);
    }

    @Override
    public Integer totalEquipmentType() {
        return equipmentTypeMapper.totalEquipmentType();
    }
}
